#include "flightjourneywidget.h"
#include "ui_flightjourneywidget.h"

FlightJourneyWidget::FlightJourneyWidget(QWidget* parent) :
    QWidget(parent),
    ui(new Ui::FlightJourneyWidget)
{
    ui->setupUi(this);
    this->setStyleSheet("background-color: lightgreen;");

    //this->setStyleSheet("background-color: #E0FFFF; border: 1px solid #A9A9A9; border-radius: 5px;");
    // Initialize the layout for segments in the scroll area
    segmentsLayout = new QVBoxLayout();
    ui->scrollAreaWidgetContents->setLayout(segmentsLayout);

    // Make the scroll area resizable to fit content
    ui->segmentScrollArea->setWidgetResizable(true);

}

FlightJourneyWidget::~FlightJourneyWidget() {
    delete ui;
}

void FlightJourneyWidget::setTotalPrice(double price) {
    ui->totalPriceLabel->setText("$" + QString::number(price, 'f', 2)+"元");
}

void FlightJourneyWidget::setTotalTime(int totalTime) {
    //ui->totalTimeLabel->setText("总时间" + totalTime);
    ui->totalMinutes->setText(QString::number(totalTime)+"分钟");
}

void FlightJourneyWidget::setTotalHours(int hour){
    ui->totalHours->setText(QString::number(hour)+"小时");
}

void FlightJourneyWidget::setTotalMinutes(int minute){
    ui->totalMinutes->setText(QString::number(minute)+"分钟");
}

void FlightJourneyWidget::setSegmentCount(int count) {
    if(count==1)
        ui->segmentCountLabel->setText("直飞");
    else
        ui->segmentCountLabel->setText("转机次数: " + QString::number(count-1));
}

void FlightJourneyWidget::addSegmentWidget(FlightSegmentWidget* segment) {
    segmentsLayout->addWidget(segment);
}
